<?php

/**
 * page actions.
 *
 * @package    jobeet
 * @subpackage page
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class pageActions extends sfActions {

    protected function makeTeaser($str, $length){
	$str = htmlspecialchars_decode($str);
	if(strlen($str) > ($length + 10)){
		$position = strpos($str, ' ', $length);
		if($position > ($length + 20)){
			$position = strpos($str, ' ', $length - 40);
		}
		return substr($str, 0, $position) . '...';
	}
	return $str . '...';
    }

    public function executeIndex(sfWebRequest $request) {
        $this->blog = Doctrine_Query::create()->select()->from('blog')->orderBy('create_time', 'desc')->fetchOne();
        $this->blogTeaser = $this->makeTeaser($this->blog->getContent(), 100);
        $this->about = PageTable::getInstance()->findOneBy('name', 'about');
        $this->aboutTeaser = $this->makeTeaser($this->about->getContent(), 100);        
    }

    public function executeAbout(sfWebRequest $request) {
        $this->blog = BlogTable::getInstance()->findAll();
        $this->page = PageTable::getInstance()->findOneBy('name', 'about');
        if(!$this->page){
            $this->redirect("@homepage"); 
        }
    }

    public function executeBlog(sfWebRequest $request) {
        $this->blog = BlogTable::getInstance()->findAll();
        $this->actuallNews = $this->blog[0];
        if($request->getParameter('title')){
            $this->actuallNews = BlogTable::getInstance()->findOneBy('title', $request->getParameter('title'));
        }
    }

}
